$(function(){
	$(".coll_body").eq(2).show();
	$(".coll_body").eq(2).children('a').eq(1).addClass("active");
	$(".Collapsing").eq(2).children('a').children('span').addClass("rotate");
	$(".Collapsing").eq(2).click(function(){
		$(".Collapsing").eq(2).toggleClass("active");
		$(this).children('.coll_body').children('a').eq(1).toggleClass("active");
	})
})
//	维护人员列表
	var pageSize = 15;
	var currentPage = 1; 
	ajaxTest(currentPage);
	
	function ajaxTest(currentPage) {
		$.ajax({
				type:"post",
				url:serverIP+"/user/maint/list",
				dataType:"json",
				xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
	            data: {page:currentPage,pageSize:pageSize},
				success:function (data) {
					let result=data.data.list.result;
					var strVar = "";
					result.map(function(u){
						var status=u.status;
						var workStatus=u.workStatus;
						if(status=="01"){
							status="启用";
						}else{
							status="停用";
						}
						if(workStatus=="01"){
							workStatus="内勤";
						}else{
							workStatus="外勤";
						}
						strVar += "              <tr>";
					    strVar += "                <td>"+u.maintId+"<\/td>\n";
					    strVar += "                <td>"+u.name+"<\/td>\n";
					    strVar += "                <td>"+u.userName+"<\/td>\n";
					    strVar += "                <td>"+u.phone+"<\/td>\n";
					    strVar += "                <td>"+workStatus+"<\/td>\n";
					    strVar += "                <td>"+status+"<\/td>\n";
					    strVar += "                <td>"+u.remark+"<\/td>\n";
					    strVar += "                <td class=\"noExl\">\n"; 
					    strVar += "                		<div>\n"; 
					    strVar += "                			<span class=\"btn edit\" value="+u.maintId+">\n"; 
					    strVar += "                				<i class=\"icon-edit\"></i>编辑\n"; 
					    strVar += "                			</span>\n"; 
					    strVar += "                			<span class=\"btn delete\" value="+u.maintId+">\n"; 
					    strVar += "                			<i class=\"icon-trash\"></i>删除\n"; 
					    strVar += "                			</span>\n";
					    strVar += "                		</div>\n";
					    strVar += "                <\/td>\n"; 
					    strVar += "             <\/tr>";
					})
					$('.print-tbody').html(strVar);
				//分页
					$("#page").paging({
						pageNo: data.data.list.curPage,
						totalPage: data.data.list.totalPage,
						totalSize: data.data.list.totalRow,
						callback: function(currentPage) {
							ajaxTest(currentPage); 
						}
					});
				}
		})
	}
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
}
$('.add').click(function(){
	window.location.href="addmaintainer.html";
})
$("body").on("click",".edit",function(){
	var mid=$(this).attr("value");
	window.location.href="editmaintainer.html?mid="+mid;
})
$("body").on("click",".delete",function(){
	if(confirm("确定要删除本条信息么")){
		var mid=$(this).attr("value");
		$.ajax({  
	        type : "POST",  
	        url : serverIP+'/user/maint/del',  
	        data : {
	        	maintId:mid
	        },
	        xhrFields: {
	            withCredentials: true    // 设置sessionId相同
	        },
	        success : function(){  
	        	window.location.reload();
	        }  
	    });
	}
}); 